# 1. Import  standard lib
import os
from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand


# 2. Module Created by oneself
from blog import create_app
from blog.models import db, User, Post, Comment, Tag, Role


#: Get the Env of named `BLOG_ENV` from os-envirron, default return `dev` string
#: evn_name : virtual environment name
env_name = 'BLOG_ENV'
env = os.environ.get('%s' % env_name, 'dev')
 
#: `capitalize()` return a string of enable first letter Upper
app = create_app('blog.config.%sConfig' % env.capitalize())

#: User to manager a `app`
manager = Manager(app)

#: Used to database manaer
migrate = Migrate(app, db)

# Create a cli for running the development_env `server`
manager.add_command("server", Server(host='127.0.0.1', port=8080))
manager.add_command("db_migrate", MigrateCommand)


@manager.shell
def make_shell_context():

	return dict(app = app,
				db = db,
				User = User,
				Post = Post,
				Comment = Comment,
				Tag = Tag,
				Role = Role)


if __name__ == '__main__':
	manager.run()